fix: Add ResourceNotFoundException handler for structured 404 responses [MDD-78]#370
Open
devin-ai-integration[bot] wants to merge 2 commits intomasterfrom
Open
Conversation
Add @ExceptionHandler for ResourceNotFoundException in CustomizeExceptionHandler to return structured JSON {"message": "Resource not found"} instead of raw 404. Add parallel handling in GraphQLCustomizeExceptionHandler with NOT_FOUND error type. Add test cases for profile not found, follow nonexistent user, and unfollow nonexistent user scenarios. Addresses MDD-78. Co-Authored-By: unknown <>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Co-Authored-By: unknown <>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix: Add structured 404 responses for ResourceNotFoundException [MDD-78]
Summary
Adds explicit
@ExceptionHandlerforResourceNotFoundExceptionin the REST exception handler and parallel handling in the GraphQL exception handler, so that invalid username lookups (and all other resource-not-found scenarios) return a structured{"message": "Resource not found"}JSON body instead of a raw, empty 404.Changes:
CustomizeExceptionHandler: New handler method returningHttpStatus.NOT_FOUNDwith a JSON body, following the existingInvalidAuthenticationExceptionpattern.GraphQLCustomizeExceptionHandler: Newelse ifbranch returning aTypedGraphQLErrorwithErrorType.NOT_FOUND, inserted before the default handler fallback.ProfileApiTest: Three new test cases covering GET profile, POST follow, and DELETE unfollow with nonexistent usernames.This fix applies application-wide to all endpoints that throw
ResourceNotFoundException(ProfileApi, ArticleApi, CommentsApi, ArticleFavoriteApi, etc.).Updates since last revision
import static org.mockito.ArgumentMatchers.anyfromProfileApiTest.java.@ExceptionHandlertakes precedence over the@ResponseStatusannotation on the exception class, and the structured JSON body is returned correctly:GET /profiles/nonexistent_user→404 {"message":"Resource not found"}POST /profiles/nonexistent_user/follow(with auth) →404 {"message":"Resource not found"}DELETE /profiles/nonexistent_user/follow(with auth) →404 {"message":"Resource not found"}Review & Testing Checklist for Human
GraphQLCustomizeExceptionHandlerchange has no corresponding test. Consider whether a GraphQL-layer test should be added for the NOT_FOUND path to guard against regressions.@ResponseStatusvs@ExceptionHandlerprecedence:ResourceNotFoundExceptionhas@ResponseStatus(HttpStatus.NOT_FOUND)on the class. Local testing confirmed the@ExceptionHandlerwins and the structured body is returned, but verify this holds in your deployment environment as well since Spring Boot version or configuration differences could affect precedence../gradlew bootRun), register a user, then:{"message": "Resource not found"}.Notes